Images taken by means for storing digital images, such as digital cameras, camera phones, or other cameras equipped with a single complementary metal-oxide semiconductor (CMOS) or with a single charge coupled device (CCD), do not comprise all colour component values for each pixel. Because the number of image sensors is decisive with respect to the price and the size of the device, it is obvious that the aim is to use only one (in some situations more than one can be used as well) image sensor in smaller devices (camera devices), wherein a so-called colour filter array (CFA), such as the Bayer matrix, is needed for forming the image.
The Bayer matrix is a common colour array, in which only one colour is sampled in each pixel and which causes that the other colours of the colour system are lacking from each pixel. For example in the RGB colour system (Red, Green Blue), half of the pixels in the Bayer matrix form the green colour component and the other half of the pixels form the blue and the red colour component, and the values of the other colour tones are lacking from each pixel. This creates a need to interpolate the missing colour samples so that the image can be stored in its complete format.
In the text, when referring to colours, the known RGB colour system will be used, which defines the colour by means of the relationship between red (R), green (G) and blue (B). However, it will be obvious that the colour component can also be described by the CMY colour system (Cyan-Magenta-Yellow), in which the colour is formed by values of cyan (C), magenta (M) and yellow (Y). The colour system can also be any other corresponding system.
The conversion of an image in the Bayer matrix format to an RGB image request the interpolation of the missing colour values in each pixel. The interpolation system can be exemplified with an interpolation system utilizing the nearest neighbour pixels (the nearest neighbour method), in which for example the interpolation of the missing blue and red colours is made according to the nearest neighbour pixel of the same colour, as well as with bilinear interpolation, which has been improved so that the interpolation of green is controlled by means of the other colour components. We shall next describe this method as an example. Below, four possible situations will be presented for the position of the colour components in the Bayer matrix:
                    a        )                                                                                                                b        )                                                                                                                c        )                                                                                                                d        )                                                                                G                      B        ⁢                                  ⁢        1                    G                                          G                      R        ⁢                                  ⁢        1                    G                                                  B        ⁢                                  ⁢        1                    G                      B        ⁢                                  ⁢        2                                                        R        ⁢                                  ⁢        1                    G                      R        ⁢                                  ⁢        2                                R        ⁢                                  ⁢        1                    G                      R        ⁢                                  ⁢        2                                                        B        ⁢                                  ⁢        1                    G                      B        ⁢                                  ⁢        2                                                G              R              G                                                  G        ⁢                                              B              G                  G                      B        ⁢                                  ⁢        2                    G                                          G                      R        ⁢                                  ⁢        2                    G                                                  B        ⁢                                  ⁢        3                    G                      B        ⁢                                  ⁢        4                                                        R        ⁢                                  ⁢        3                    G                      R        ⁢                                  ⁢        4            
When the missing R and B values are computed for the green pixel G, as under the points (a) and (b), the average values are computed for two neighbours of the same colour. For example under point (a), the value of the blue component B in the green central pixel is the average value of the blue pixels above and under the green pixel G (B(G)=(B1+B2)/2). In a corresponding manner, the value of the red component R in the green central pixel is the average value of the red pixels R adjacent to the green pixel G (R(G)=(R1+R2)/2).
The case in point (c) is one where the blue colour is interpolated for a red pixel R. In this case, the average value is taken from the four closest blue pixels B (B(R)=(B1+B2+B3+B4)/4) which are located at the corners of the red pixel R. Similarly, the value of the red component R in a blue pixel B, under point (d), is obtained by computing the average value of the blue corner pixels B (R(B)=(R1+R2+R3+R4)/4).
The green component G can be interpolated by using the closest neighbour pairs. Below, two cases are presented for interpolating the green component G.
                    a        )                                                        R        ⁢                                  ⁢        1                                                                                                                                                                        b        )                                                        B        ⁢                                  ⁢        1                                                                                                                                                G        ⁢                                  ⁢        1                                                                                                                                                                                                                                G        ⁢                                  ⁢        1                                                                                        R        ⁢                                  ⁢        4                            G        ⁢                                  ⁢        4                    R                      G        ⁢                                  ⁢        2                            R        ⁢                                  ⁢        2                                                                                                                B        ⁢                                  ⁢        4                            G        ⁢                                  ⁢        4                    B                      G        ⁢                                  ⁢        2                            B        ⁢                                  ⁢        2                                                                                        G        ⁢                                  ⁢        3                                                                                                                                                                                                                                G        ⁢                                  ⁢        3                                                                                                                                                R        ⁢                                  ⁢        3                                                                                                                                                                                                                                B        ⁢                                  ⁢        3                                                                    
Under point (a), the value of the green component G is interpolated for a red pixel R. The value of the green component G is thus:
                                          G            ⁡                          (              R              )                                =                    ⁢                                    (                                                G                  ⁢                                                                          ⁢                  1                                +                                  G                  ⁢                                                                          ⁢                  3                                            )                        /            2                          ,                              if            ⁢                                                  ⁢                          abs              ⁡                              (                                                      R                    ⁢                                                                                  ⁢                    1                                    -                                      R                    ⁢                                                                                  ⁢                    3                                                  )                                              <                      abs            ⁡                          (                                                R                  ⁢                                                                          ⁢                  2                                -                                  R                  ⁢                                                                          ⁢                  4                                            )                                      ,                                        ⁢                                            (                                                G                  ⁢                                                                          ⁢                  2                                +                                  G                  ⁢                                                                          ⁢                  4                                            )                        /            2                    ,                                    if              ⁢                                                          ⁢                              abs                ⁡                                  (                                                            R                      ⁢                                                                                          ⁢                      1                                        -                                          R                      ⁢                                                                                          ⁢                      3                                                        )                                                      >                          abs              ⁡                              (                                                      R                    ⁢                                                                                  ⁢                    2                                    -                                      R                    ⁢                                                                                  ⁢                    4                                                  )                                              ,                                                ⁢                                            (                                                G                  ⁢                                                                          ⁢                  1                                +                                  G                  ⁢                                                                          ⁢                  2                                +                                  G                  ⁢                                                                          ⁢                  3                                +                                  G                  ⁢                                                                          ⁢                  4                                            )                        /            4                    ,                                    if              ⁢                                                          ⁢                              abs                ⁡                                  (                                                            R                      ⁢                                                                                          ⁢                      1                                        -                                          R                      ⁢                                                                                          ⁢                      3                                                        )                                                      =                                          abs                ⁡                                  (                                                            R                      ⁢                                                                                          ⁢                      2                                        -                                          R                      ⁢                                                                                          ⁢                      4                                                        )                                            .                                          
In other words, the effect of the red component R is taken into account in the interpolation. If the difference between R1 and R3 is smaller than the difference between R2 and R4, it is noticed that the red R is stronger in the vertical direction, wherein the average value of the vertical neighbours G1 and G3 is used for computing the desired value in the interpolation. On the other hand, if the horizontal effect is greater, the adjacent neighbours are used respectively. If the ratio of red is the same throughout, all the four neighbours are used. In connection with the blue colour component B, a similar computation is made under point (b).
Publication U.S. Pat. No. 6,549,233 B1 discloses one method for colour interpolation by means of the Bayer matrix. The method of the publication includes calculating colour intensity gradients for the image, of which the highest and lowest gradient value is determined. The gradients are calculated between the first colour locating in the centre pixel of the matrix and the similar colours spaced from that. Calculated gradients are compared to threshold value, and if a gradient exceeds said threshold value (which is formed of the average of the intensities of the colour) in that colour, the intensity value of the centre pixel is used for the pixel spaced from it.
U.S. Pat. No. 5,247,352 discloses a method for sharpening a colour image. In the method, the sharpening is based on a three-dimensional colour space, for example the Munsell colour chart. The publication presents several switch states for defining the sum of colour difference signals and at least two sharpening signals. The switch states are set by means of a colour coordinate system. The system determines the pixel locations on the basis of the colour values of the pixels. The positions of the switches are based on position data. On the basis of information transmitted by the switches, the device according to the publication can combine the desired sharpening signals with the colour difference signals. In this way, the image can be sharpened. So that the sharpening of the image would be of as good a quality as possible, there must be at least two sharp signals, red and green. In other words, in the method of the patent, the filtering of the second and the third colour components is adjusted on the basis of a value obtained from the colour space.
After the interpolation, all the colour components must be sharpened, which causes triple work for the image processing, which, in turn, requires that the processing system has a high processing capacity. The present invention improves the prior art by filtering the other colour components by utilizing the filtering result of a single colour component. In systems of prior art, the filtering in different components may cause different effects, wherein distortions may occur in the colours of the image. Also, in known sharpening functions, two kinds of undesired phenomena may occur, such as an increase in the noise and, particularly close to edges, excessive sharpening of the edge. This, in turn, causes ringing, which is manifested, for example, as a black line in connection with a white line.